package mest.controller.LGF.WarehouseTakeMaterial;

import mest.VO.LGF.WarehouseTakeMaterial.warehouse_productjob_takematerial_recordVO;
import mest.entity.User;
import mest.entity.warehouse_productjob_takematerial_record;
import mest.service.LGF.WarehouseTakeMaterial.IWarehouseTakeMaterialService;
import mest.util.ResultObj;
import mest.util.mestUtil;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-12-22 18:53
 *
 */
//Model是属于请求域
    //           @RequestMapping(value="/one",params = "method=a")
   //           @RequestMapping(value="/two1",produces = {"application/json;charset=utf-8","text/plain;charset=utf-8"})
    //参数:@RequestParam(value = "b",required = false,defaultValue = "握草尼玛")
    //         @RequestBody String(str) 输出:userCode=admin&userPassword=1234567
    //          @SessionAttributes({"a","b","c"}) 自动把该controller下所有返回页面的属性的作用域改成session
    //          @ModelAttribute标注一个方法时，指定每次跳入某个路径时该方法先执行
@CrossOrigin
@RestController
@RequestMapping(value="/warehouse_takeMaterial")
public class WarehouseTakeMaterialController {
    @Resource
    private IWarehouseTakeMaterialService iwts;

    @RequestMapping(value = "/baseSelectNofinish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectNofinish(int page, int limit) {
        Map map = iwts.baseSelectNofinish(page, limit);
        System.out.println(map.get("data"));
        return map;
    }


    @RequestMapping(value = "/baseSelectFinish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map baseSelectFinish(int page, int limit) {
        Map map = iwts.baseSelectFinish(page, limit);
        return map;
    }
    
    //    selecTakeMaterialDetail
    @RequestMapping(value="/selectTakeMaterialDetail", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map selecTakeMaterialDetail(int wtId,int page,int limit){
        System.out.println("wtId is :"+wtId);
        Map map = iwts.selectTakeMaterialDetail(wtId,page, limit);
        System.out.println(map);
        return map;
    }


    @RequestMapping(value="/selectTakeMaterialPastRecord", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public Map selectWorkFinishPastRecord(int wptId,int page,int limit){
        Map map = iwts.selectTakeMaterialOutPastRecord(wptId,page, limit);
        return map;
    }

    @PostMapping(value="/addRecord", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public ResultObj addRecord(warehouse_productjob_takematerial_recordVO wptr, HttpServletRequest request){

        try {
            wptr.setEfId(mestUtil.getUserId(request));

            //System.out.println(wptr.toString());
            int i = iwts.addRecord(wptr);

            return ResultObj.createSuccessMsg(ResultObj.UPDATE_SUCCESS);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return ResultObj.createErrorMsg(e.getMessage());
		}
    }

    @RequestMapping(value="/finish", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String finish(int wtId,int finishStatus){

        int i = iwts.updateByWTId(wtId,finishStatus);
        if(i == -2){
            return   "服务器异常";
        }else if(i == -1){
            return "更新失败";
        }else if(i>0){
            return "更新成功";
        }
        return "未知错误，请联系管理员";
    }
}
